#pragma once

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <unistd.h>
#include <cstdlib>
#include <ctime>
#include <sys/types.h>
#include <sys/wait.h>

typedef void (*task_t)();
typedef void (*work_t)(int);

const int size = 4096;
const int task_number = 7;
// 加载
void download()
{
    std::cout << "This is a downlaod task!" << std::endl;
}
// 打印
void print()
{
    std::cout << "This is a print task!" << std::endl;
}
// 刷新
void flush()
{
    std::cout << "This is a flush task!" << std::endl;
}

std::vector<task_t> task;

void load_task()
{
    task.push_back(download);
    task.push_back(print);
    task.push_back(flush);
}
void excute_task(int option_task)
{
    if (option_task < 0 || option_task >= task.size())
        return;
    task.at(option_task)();
}

void work(int rfd)
{
    int t = task_number;
    int option_task = 0;
    int n = read(rfd, &option_task, sizeof(option_task));
    if (n > 0)
    {
        excute_task(option_task);
        std::cout << "--------------------------------" << std::endl;
    }
}